package com.ttt.radioapp_contacto1009;


import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public class RadioStreamingService extends

		com.ttt.radiostreammingservice.RadioStreamingIntentService {

	public static final String BROADCAST_STOPMEDIA = "RadioStreamingService.StopMedia";
	
	private BroadcastReceiver broadcastReceiverStopMedia = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
			stopMedia();

			PendingIntent pendingIntent = PendingIntent.getBroadcast(
					context, 0, new Intent(RadioStreamingService.BROADCAST_STOPMEDIA),
					PendingIntent.FLAG_NO_CREATE);
		
			if (pendingIntent != null){
				pendingIntent.cancel();
			}
		}
	};
	
	

	@Override
	protected int getIcon() {
		return R.drawable.tray_icon;
	}

	@Override
	protected Class<?> getActivityClass() {
		return MainActivity.class;
	}

	@Override
	protected String getNotificationTitle() {
		return "Estas escuchando Contacto FM 100.9";
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		int result = super.onStartCommand(intent, flags, startId);
		registerReceiver(broadcastReceiverStopMedia, new IntentFilter(BROADCAST_STOPMEDIA));
		return result;
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		unregisterReceiver(broadcastReceiverStopMedia);
	}
	
}